import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/confi g/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    host: '0.0.0.0', // 允许外部访问
    port: 5173,       // 你本地的端口
    cors: true, // 启用跨域
    strictPort: false,
    allowedHosts:[
      'localhost', // 默认允许的本地主机
      '11058878.r6.cpolar.top', // 添加这个域名
    ],
    proxy: {
      '/UserApi': {
        target: 'http://localhost:5000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/UserApi/, '')
      },
      //Ai----------------------------------
      // port: 3001,
      // hmr: true,
      // proxy: {
      //
      //   "/api": {
      //     target: "http://localhost:6060",
      //     changeOrigin: true,
      //     rewrite: (path) => path.replace(/^\/api/, '/api'),
      //   }
      "/api": {
        target: "http://localhost:7080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api'),
      },
      // },
      // -------------------------------------------------------------
      '/adminApi': {
        target: 'http://localhost:4000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/adminApi/, '')
      },
      '/DeliveryApi': {
        target: 'http://localhost:7000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/DeliveryApi/, '')
      },
    }
  }
})
